package com.my.mall.client.shippingAddress.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.mall.client.shippingAddress.dto.ShippingAddressClientDTO;
import com.my.mall.client.shippingAddress.service.ShippingAddressClientService;
import com.my.mall.client.shippingAddress.vo.ShippingAddressClientVo;
import com.my.mall.common.R;

@Controller
@RequestMapping("client/shippingAddress")
public class ShippingAddressClientController {
	@Autowired
	ShippingAddressClientService shippingAddressClientService;

	@RequestMapping("selectShippingAddressList")
	@ResponseBody
	public List<ShippingAddressClientVo> selectShippingAddressList(int userId) {
		return shippingAddressClientService.selectShippingAddressList(userId);
	}
	
	@RequestMapping("getShippingAddress/{addressId}")
	@ResponseBody
	public ShippingAddressClientVo getShippingAddress(@PathVariable("addressId") int id) {
		return shippingAddressClientService.getShippingAddress(id);
	}

	@RequestMapping("save")
	@ResponseBody
	public R save(@RequestBody ShippingAddressClientDTO address) {
		int result = 0;
		if (address.getId() == 0)
			result = shippingAddressClientService.save(address);
		else
			result = shippingAddressClientService.update(address);

		if (result == 1)
			return R.ok();
		else
			return R.error("系统故障！");
	}

	@RequestMapping("del/{id}")
	@ResponseBody
	public R del(@PathVariable("id") int id) {
		int result = shippingAddressClientService.del(id);
		if (result == 1)
			return R.ok();
		else
			return R.error("系统故障");
	}
}